﻿' LibWowArmory
' by Ronald M. Clifford (roncli@roncli.com)
'
' This source code is released under the GNU Library General Public License (LGPL) Version 2.1.

Imports System
Imports System.Collections.ObjectModel
Imports System.Linq
Imports Newtonsoft.Json
Imports roncliProductions.LibWowArmory.Enums
Imports roncliProductions.LibWowArmory.Extensions
Imports roncliProductions.LibWowArmory.Internationalization

Namespace roncliProductions.LibWowArmory.Data

    ''' <summary>
    ''' A class that retrieves character race information from the Blizzard WoW API.
    ''' </summary>
    ''' <remarks></remarks>
    Public Class CharacterRaces
        Inherits WowArmoryData

        Private crRaces As New Schema.CharacterRaces.races

#Region "WowArmoryData Overrides"

#Region "Public Properties"

        ''' <summary>
        ''' The length of time the data should be cached for, defaulting to 30 days for character race information.
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Overrides Property CacheLength As New TimeSpan(30, 0, 0, 0)

#End Region

#Region "Protected Properties"

        Protected Overrides ReadOnly Property CacheKey As String
            Get
                Return "LibWowArmory.CharacterRaces"
            End Get
        End Property

        Protected Overrides ReadOnly Property URI As Uri
            Get
                Return New Uri("/api/wow/data/character/races", UriKind.Relative)
            End Get
        End Property

#End Region

#End Region

#Region "Properties"

        Private colRaces As Collection(Of Race)
        ''' <summary>
        ''' A list of player races as returned from the Blizzard WoW API.
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public ReadOnly Property Races As Collection(Of Race)
            Get
                Return colRaces
            End Get
        End Property

#End Region

#Region "Methods"

        ''' <summary>
        ''' A default constructor to retrieve character race information from the Blizzard WoW API.
        ''' </summary>
        ''' <remarks></remarks>
        Public Sub New()
            Load()
        End Sub

        ''' <summary>
        ''' A constructor to retrieve character class information for a specific region and language from the Blizzard WoW API.
        ''' </summary>
        ''' <param name="rRegion"></param>
        ''' <param name="lLanguage"></param>
        ''' <remarks></remarks>
        Public Sub New(rRegion As Region, lLanguage As Language)
            Region = rRegion
            Language = lLanguage
            Load()
        End Sub

        ''' <summary>
        ''' Loads the character races.
        ''' </summary>
        ''' <remarks></remarks>
        Public Sub Load()
            MyBase.Retrieve()
            crRaces = CType(JsonConvert.DeserializeObject(Data, GetType(Schema.CharacterRaces.races)), Schema.CharacterRaces.races)
            colRaces = (From r In crRaces.races
                        Select New Race(r.id, r.mask, r.side.GetSide(), r.name)
                        ).ToCollection()
        End Sub

#End Region

    End Class

End Namespace
